/* eslint-disable no-confusing-arrow */
import React from 'react';
import { history } from 'umi';
import moment from 'moment';
import { debounce } from 'lodash';
import { Spin } from 'antd';
import { stringify } from 'qs';
import request from '@/utils/request';
import { getEmployeeInfoList } from '@/services/components/userform';
import clone from 'lodash/clone';
import { getOrganization, hideSalaryTable } from '@/utils/utils';
/**
 * 这里可以在渲染之前修改自定义表单 json，必须返回 json
 * @param json
 * @param country  国家：zh/sg
 * @param formType  申请类型，从json.key中截取
 */
import {
    // getOptionData,
    initModifyJson
} from '@/pages/Flow/Mine/ApplyPage/utils';
import {
    modifyComponent,
    modifyConfig,
    modifyItemProps,
    modifyParams,
    modifyProps
} from '@/pages/Flow/Mine/Apply/utils';
import {
    companysearchCandidate as searchCandidate,
    getPostListByCondition as searchPostList
} from '@/services/flowMine/apply';
import styles from './ApplyPage.less';
import applyType from './consts';

const { TYPE_GO_OUT } = applyType;

const modifyJson = async ({
    json,
    country,
    form,
    onlyShowForm,
    restQuery,
    currentUser,
    setTakeUsers,
    setPostList,
    setLeaders,
    setRecorder,
    setFetching,
    setOriginInstitutionName
}) => {
    const tmpJson = initModifyJson(json, country, form, restQuery);
    let { fields } = tmpJson;
    const { key } = tmpJson;
    const formType = key.split('-')[1];

    // 外出
    if (formType === TYPE_GO_OUT) {
        fields = modifyConfig(
            'startTime',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 3
                }
            },
            fields
        );
        fields = modifyConfig(
            'endTime',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 3
                }
            },
            fields
        );
    } else if (formType === applyType.TYPE_LEAVE) {
        fields = modifyProps(
            'startTime',
            {
                timeSpread: true
            },
            fields
        );
        fields = modifyProps(
            'endTime',
            {
                timeSpread: true
            },
            fields
        );
        fields = modifyParams(
            'attachment',
            {
                condition() {
                    const attachmentRequired = form.getFieldValue('leaveType');
                    if (attachmentRequired === 'CommonSick') {
                        return {
                            required: true
                        };
                    }
                    return {
                        required: false
                    };
                }
            },
            fields
        );
        fields = modifyConfig(
            'attachment',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            const attachmentRequired = form.getFieldValue('leaveType');
                            if (attachmentRequired === 'CommonSick' && (!value || value.allFileList.length === 0)) {
                                callback('请选择附件！');
                            } else {
                                callback();
                            }
                        }
                    }
                ]
            },
            fields
        );
    } else if (formType === applyType.TYPE_OVER_TIME) {
        fields = modifyConfig(
            'startTime',
            {
                initialValue: {
                    disabled: true,
                    unit: 3
                }
            },
            fields
        );
        fields = modifyConfig(
            'endTime',
            {
                initialValue: {
                    disabled: true,
                    unit: 3
                }
            },
            fields
        );
    } else if (formType === applyType.TYPE_ON_BUSINESS) {
        // 出差都是半天
        fields = modifyConfig(
            'startTime',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 2,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'endTime',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 2,
                    type: 'endTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'returnToWork',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 1,
                    country,
                    type: 'returnToWork',
                    dayType: 'am'
                }
            },
            fields
        );
        fields = modifyProps(
            'returnToWork',
            {
                allowClear: true
            },
            fields
        );
        fields = modifyProps(
            'totalExpense',
            {
                disabled: true
            },
            fields
        );
        fields = modifyProps(
            'hotelExpense',
            {
                precision: 2,
                min: 0
            },
            fields
        );
        fields = modifyProps(
            'transportExpense',
            {
                precision: 2,
                min: 0
            },
            fields
        );
        fields = modifyProps(
            'businessAllowance',
            {
                precision: 2,
                min: 0
            },
            fields
        );
        fields = modifyProps(
            'otherExpense',
            {
                precision: 2,
                min: 0
            },
            fields
        );
    } else if (formType === applyType.TYPE_RESIGN_IN) {
        // 增加查看打卡记录
        fields = modifyItemProps(
            'startTime',
            {
                className: styles.bksj,
                extra: !onlyShowForm && (
                    <a
                        href="#"
                        onClick={e => {
                            e.preventDefault();
                            history.push('/personal/portal/attendance/mine/abnormal');
                        }}
                    >
                        查看缺卡记录
                    </a>
                )
            },
            fields
        );
        // 补卡申请是没有上下午的
        fields = modifyConfig(
            'startTime',
            {
                initialValue: {
                    unit: 3,
                    disabled: onlyShowForm
                }
            },
            fields
        );
    } else if (formType === applyType.TYPE_ON_RECRUIT) {
        fields = modifyConfig(
            'demandCompanyId',
            {
                initialValue: currentUser.companyName
            },
            fields
        );
        fields = modifyConfig(
            'workNature',
            {
                initialValue: country === 'zh' ? 'full_time' : ''
            },
            fields
        );
        fields = modifyConfig(
            'requireSex',
            {
                initialValue: '3'
            },
            fields
        );
        fields = modifyProps(
            'demandDepartmentId',
            {
                onChange: debounce(value => {
                    searchPostList({
                        departmentId: (value && clone(value).pop()) || ''
                    }).then(response => {
                        if (response.code === 10000) {
                            const newDate = response.data.map(item => ({ ...item, id: item.id.toString() }));
                            form.setFieldsValue({
                                recruitPost: undefined,
                                postLevel: undefined
                            });
                            setPostList(newDate);
                        }
                    });
                }, 400)
            },
            fields
        );

        // 招聘申请-岗位列表-模糊搜索
        // 需求：先通过需求部门获取公司id，然后进行搜索职位
        fields = modifyProps(
            'recruitPost',
            {
                onSearch: debounce(value => {
                    setFetching(true);
                    const departmentId = clone(form.getFieldValue('demandDepartmentId'));
                    searchPostList({
                        postName: value,
                        departmentId: (departmentId && clone(departmentId).pop()) || ''
                    }).then(response => {
                        if (response.code === 10000) {
                            const newDate = response.data.map(item => ({ ...item, id: item.id.toString() }));
                            setPostList(newDate);
                            setFetching(false);
                        }
                    });
                }, 400)
            },
            fields
        );
        // offer申请-岗位列表-模糊搜索
        fields = modifyProps(
            'entryPost',
            {
                onSearch: debounce(value => {
                    if (value) {
                        setFetching(true);
                        searchPostList({
                            postName: value,
                            companyId: currentUser.companyId
                        }).then(response => {
                            if (response.code === 10000) {
                                const newDate = response.data.map(item => {
                                    item.id = item.id.toString();
                                    return item;
                                });
                                setPostList(newDate);
                                setFetching(false);
                            }
                        });
                    } else {
                        setPostList([]);
                    }
                }, 400)
            },
            fields
        );
        fields = modifyConfig(
            'applyDate',
            {
                initialValue: moment().format('YYYY-MM-DD')
            },
            fields
        );
        fields = modifyProps(
            'totalNums',
            {
                precision: 0,
                min: 0
            },
            fields
        );
        fields = modifyProps(
            'workNums',
            {
                precision: 0,
                min: 0
            },
            fields
        );
        fields = modifyProps(
            'requireNums',
            {
                precision: 0,
                min: 0
            },
            fields
        );
        fields = modifyParams(
            'reason1',
            {
                layoutSpan: () =>
                    form.getFieldValue('reason2') === 'supply_for_other' ||
                    form.getFieldValue('reason2') === 'supply_for_quit' ||
                    form.getFieldValue('reason2') === 'no_buget'
                        ? 24
                        : ''
            },
            fields
        );
        fields = modifyComponent(
            'reason2',
            {
                condition() {
                    return form.getFieldValue('reason1') !== 'quitNeed';
                }
            },
            fields
        );
        fields = modifyComponent(
            'otherReason',
            {
                // 其他申请/无预算/离职补岗
                condition: () =>
                    form.getFieldValue('reason2') === 'supply_for_other' ||
                    form.getFieldValue('reason2') === 'no_buget' ||
                    form.getFieldValue('reason2') === 'supply_for_quit' ||
                    form.getFieldValue('reason1') === 'quitNeed',
                conditionProps() {
                    if (form.getFieldValue('reason1') === 'quitNeed') {
                        return {
                            placeholder: '离职人员姓名'
                        };
                    }
                    return {};
                }
            },
            fields
        );
        fields = modifyComponent(
            'languageAbilityOther',
            {
                condition: () => {
                    const value = form.getFieldValue('languageAbility');
                    return Array.isArray(value) && value.includes('other');
                }
            },
            fields
        );
        fields = modifyComponent(
            'workNatureOther',
            {
                condition: () => form.getFieldValue('workNature') === 'other'
            },
            fields
        );
        // fields = modifyProps(
        //     'postLevel',
        //     {
        //         options: getOptionData(levelType || [], {
        //             key: 'dictValue',
        //             label: 'dictName'
        //         })
        //     },
        //     fields
        // );
        fields = modifyConfig(
            'salaryStart',
            {
                getValueFromEvent: event => {
                    const { value } = event.target;
                    if (!value) return '';
                    if (Number.isNaN(parseInt(value, 10))) {
                        return '';
                    }
                    return value;
                },
                initialValue: ''
            },
            fields
        );
        fields = modifyConfig(
            'salaryEnd',
            {
                getValueFromEvent: event => {
                    const { value } = event.target;
                    if (!value) return '';
                    if (Number.isNaN(parseInt(value, 10))) {
                        return '';
                    }
                    return value;
                },
                initialValue: ''
            },
            fields
        );
        fields = modifyConfig(
            'salaryMonth',
            {
                getValueFromEvent: event => {
                    const { value } = event.target;
                    if (!value) return '';
                    if (Number.isNaN(parseInt(value, 10))) {
                        return '';
                    }
                    return value;
                },
                initialValue: ''
            },
            fields
        );
        fields = modifyConfig(
            'entryDate',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'entryDateEnd',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
    } else if (formType === applyType.TYPE_ON_OFFER) {
        // fields = modifyProps(
        //     'talentName',
        //     {
        //         disabled: restQuery.talentId ? true : onlyShowForm
        //     },
        //     fields
        // );

        // offer表单增加展示薪资参考
        if (!hideSalaryTable) {
            const targetIndex = fields.findIndex(item => item.id === 'remark');
            if (targetIndex) {
                const salaryRefItem = {
                    fieldType: 'FormField',
                    id: 'salaryRef',
                    name: '薪资参考',
                    type: 'custom.SalaryRefTable',
                    params: {
                        title: '薪资福利',
                        layoutSpan: 24,
                        component: {
                            props: {
                                postId: undefined,
                                companyId: currentUser.companyId
                            }
                        }
                    }
                };
                fields.splice(targetIndex, 0, salaryRefItem);
            }
        }

        fields = modifyProps(
            'talentExperience',
            {
                step: 0.1,
                precision: 1
            },
            fields
        );
        fields = modifyProps(
            'attachment',
            {
                businessCode: 'SysRecruit',
                categoryCode: 'offerFile'
            },
            fields
        );
        fields = modifyConfig(
            'talentBirth',
            {
                initialValue: {
                    // disabled: true,
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'entryDate',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'contractBeginDate',
            {
                initialValue: {
                    disabled: onlyShowForm,
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyProps(
            'talentName',
            {
                onSearch: debounce(value => {
                    if (value) {
                        setFetching(true);
                        searchCandidate({
                            candidateName: value,
                            companyId: currentUser.companyId,
                            searchStage: 'offer'
                        }).then(response => {
                            if (response.code === 10000) {
                                setTakeUsers(response.data);
                                setFetching(false);
                            }
                        });
                    } else {
                        setTakeUsers([]);
                    }
                }, 400)
            },
            fields
        );
        fields = modifyComponent(
            'talentName',
            {
                conditionProps(_, newFetching) {
                    return {
                        notFoundContent: newFetching ? <Spin size="small" /> : null
                    };
                }
            },
            fields
        );
        fields = modifyProps(
            'teacherId',
            {
                onSearch: debounce(value => {
                    if (value) {
                        setFetching(true);
                        request('/api/oa/v1/employee/getservicepersonlist', {
                            method: 'POST',
                            data: {
                                companyId: currentUser.companyId,
                                userName: value
                            }
                        }).then(response => {
                            if (response.code === 10000) {
                                setFetching(false);
                                setLeaders(response.data);
                            }
                        });
                    } else {
                        setLeaders([]);
                    }
                }, 400)
            },
            fields
        );
        fields = modifyComponent(
            'teacherId',
            {
                conditionProps(_, newFetching) {
                    return {
                        notFoundContent: newFetching ? <Spin size="small" /> : null
                    };
                }
            },
            fields
        );
        fields = modifyProps(
            'backRecorderId',
            {
                onSearch: debounce(value => {
                    if (value) {
                        setFetching(true);
                        getEmployeeInfoList({
                            companyId: currentUser.companyId,
                            userName: value
                        }).then(response => {
                            if (response.code === 10000) {
                                setFetching(false);
                                setRecorder(response.data.map(item => ({ ...item, userCode: item.employeeCode })));
                            }
                        });
                    } else {
                        setRecorder([]);
                    }
                }, 400)
            },
            fields
        );
        fields = modifyComponent(
            'backRecorderId',
            {
                conditionProps(_, newFetching) {
                    return {
                        notFoundContent: newFetching ? <Spin size="small" /> : null
                    };
                }
            },
            fields
        );
        fields = modifyConfig(
            'talentExperience',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            if (value && `${value}`.length > 10) {
                                callback('最大只能输入 10 个字符！');
                            } else {
                                callback();
                            }
                        }
                    }
                ]
            },
            fields
        );
        fields = modifyConfig(
            'tryDuration',
            {
                initialValue: getOrganization(currentUser.companyId)?.area === 'cn' ? 'six_month' : 'three_month'
            },
            fields
        );

        const find = fields.find(field => field.id === 'note');
        if (find) {
            fields = modifyProps(
                'note',
                {
                    children: (
                        <span
                            // eslint-disable-next-line react/no-danger
                            dangerouslySetInnerHTML={{
                                __html: find.params.component.props.children
                            }}
                        />
                    )
                },
                fields
            );
        }
    } else if (formType === applyType.TYPE_ON_NEWS) {
        fields = modifyConfig(
            'createTime',
            {
                initialValue: moment().format('YYYY-MM-DD HH:mm')
            },
            fields
        );
        fields = modifyConfig(
            'newsType',
            {
                initialValue: 'cNews'
            },
            fields
        );
        fields = modifyParams(
            'newsType',
            {
                layoutSpan: 12
            },
            fields
        );
        fields = modifyParams(
            'releaseTime',
            {
                layoutSpan: 24
            },
            fields
        );
        fields = modifyProps(
            'releaseTime',
            {
                style: {
                    width: '36.33333333%'
                }
            },
            fields
        );
        fields = modifyItemProps(
            'attachmentRec',
            {
                className: 'attachmentRec',
                style: {
                    marginBottom: 24
                }
            },
            fields
        );
        fields = modifyItemProps(
            'attachmentNews',
            {
                className: 'attachmentNews',
                style: {
                    marginBottom: 24
                }
            },
            fields
        );
        fields = modifyParams(
            'createTime',
            {
                layoutSpan: 24
            },
            fields
        );
        fields = modifyConfig(
            'labelCn',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            if (value) {
                                const hasLengthThan20 = value.some(item => item.value && item.value.length > 20);

                                if (hasLengthThan20) {
                                    callback('标签长度不能超过 20 个字符！');
                                } else {
                                    callback();
                                }
                            } else {
                                callback();
                            }
                        }
                    }
                ]
            },
            fields
        );
        fields = modifyConfig(
            'labelEn',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            if (value) {
                                const hasLengthThan20 = value.some(item => item.value && item.value.length > 20);

                                if (hasLengthThan20) {
                                    callback('标签长度不能超过 20 个字符！');
                                } else {
                                    callback();
                                }
                            } else {
                                callback();
                            }
                        }
                    }
                ]
            },
            fields
        );
    } else if (formType === applyType.TYPE_ON_SYSTEM) {
        // 获取实施范围和获取日期的初始值
        fields = modifyConfig(
            'companyId',
            {
                initialValue: currentUser.companyId
            },
            fields
        );
        // 获取实施范围和获取日期的初始值
        fields = modifyConfig(
            'companyName',
            {
                initialValue: currentUser.companyName
            },
            fields
        );
        fields = modifyConfig(
            'applyDate',
            {
                initialValue: moment().format('YYYY-MM-DD')
            },
            fields
        );
        fields = modifyProps(
            'startTime',
            {
                style: {
                    marginTop: '40px'
                }
            },
            fields
        );
        fields = modifyProps(
            'endTime',
            {
                style: {
                    marginTop: '40px'
                }
            },
            fields
        );
        // 是否显示已有制度更新内容判断
        fields = modifyComponent(
            'originInstitutionId',
            {
                condition: () =>
                    form.getFieldValue('releaseType') === 'update' &&
                    form.getFieldValue('institutionType') !== undefined
            },
            fields
        );
        // 已有制度模糊查询loading效果
        fields = modifyComponent(
            'originInstitutionId',
            {
                conditionProps(_, fetchings) {
                    return {
                        notFoundContent: fetchings ? <Spin size="small" /> : null
                    };
                }
            },
            fields
        );
        // 模糊查询change
        fields = modifyProps(
            'originInstitutionId',
            {
                onSearch: debounce(value => {
                    setFetching(true);
                    request(
                        `/api/oa/v1/institutions/origin?${stringify({
                            institutionType: form.getFieldValue('institutionType'),
                            companyId: currentUser.companyId,
                            keyword: value
                        })}`,
                        {
                            method: 'GET'
                        }
                    ).then(response => {
                        if (response.code === 10000) {
                            setFetching(false);
                            setOriginInstitutionName(response.data);
                        }
                    });
                }, 400)
            },
            fields
        );
        // 制度类型修改后触发校验发布类型
        fields = modifyConfig(
            'institutionType',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            form.validateFields(['releaseType']);
                            if (value) {
                                callback();
                            } else {
                                callback('请选择制度类型');
                            }
                        }
                    }
                ]
            },
            fields
        );
        // 制度文件添加class
        fields = modifyItemProps(
            'institutionAttachment',
            {
                className: 'institutionAttachment'
            },
            fields
        );
        // 已有制度修改 需要先确保已选择制度类型的校验
        fields = modifyConfig(
            'releaseType',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            if (value === 'update' && form.getFieldValue('institutionType') === undefined) {
                                callback('请先选择制度类型！');
                            } else {
                                callback();
                            }
                        }
                    }
                ]
            },
            fields
        );
        // 后端要求额外传一个id字段、一个companyName
        fields = modifyComponent(
            'originInstitutionName',
            {
                condition: () => false
            },
            fields
        );
        // fields = modifyProps(
        //     'originInstitutionId',
        //     {
        //         style: {
        //             display: 'none'
        //         }
        //     },
        //     fields
        // );
        fields = modifyProps(
            'companyId',
            {
                style: {
                    display: 'none'
                }
            },
            fields
        );
        // fields = modifyComponent(
        //     'companyId',
        //     {
        //         condition: () => false
        //     },
        //     fields
        // );
        // 是否显示指定生效日期 开始结束时间内容判断
        fields = modifyComponent(
            'startTime',
            {
                condition: () => form.getFieldValue('auditEffectFlag') === 'no'
            },
            fields
        );
        fields = modifyComponent(
            'endTime',
            {
                condition: () => form.getFieldValue('auditEffectFlag') === 'no'
            },
            fields
        );
        // 修改接口返回值，config中插入initialValue
        fields = modifyConfig(
            'startTime',
            {
                initialValue: {
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'endTime',
            {
                initialValue: {
                    unit: 1,
                    type: 'startTime',
                    country
                }
            },
            fields
        );
        fields = modifyConfig(
            'releaseType',
            {
                initialValue: 'new'
            },
            fields
        );
        fields = modifyConfig(
            'auditEffectFlag',
            {
                initialValue: 'yes'
            },
            fields
        );
        // 限制已有制度模糊查询必填
        fields = modifyConfig(
            'originInstitutionId',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            if (value) {
                                callback();
                            } else {
                                callback('请搜索已有制度');
                            }
                        }
                    }
                ]
            },
            fields
        );
        // 限制关键字tag
        fields = modifyConfig(
            'keywords',
            {
                rules: [
                    {
                        validator(_, value, callback) {
                            if (value) {
                                const hasLengthThan20 = value.some(item => item.value && item.value.length > 20);
                                if (hasLengthThan20) {
                                    callback('标签长度不能超过 20 个字符！');
                                } else if (value.length > 5) {
                                    callback('只能设置5个关键字，请删除！');
                                } else {
                                    callback();
                                }
                            } else {
                                callback();
                            }
                        }
                    }
                ]
            },
            fields
        );
        fields = modifyConfig(
            'institutionType',
            {
                initialValue: restQuery.type
            },
            fields
        );
    } else if (
        [
            applyType.ADD_GRADE_TYPE,
            applyType.ADD_GRADE,
            applyType.EDIT_GRADE,
            applyType.EDIT_GRADE_TYPE,
            applyType.REMOVE_GRADE,
            applyType.REMOVE_GRADE_TYPE
        ].includes(formType)
    ) {
        fields = modifyComponent(
            'startTime',
            {
                condition: () => form.getFieldValue('auditEffectFlag') === '1'
            },
            fields
        );

        if (
            [
                applyType.ADD_GRADE,
                applyType.EDIT_GRADE // 删除职级不用校验，因为会影响历史数据
            ].includes(formType)
        ) {
            fields = modifyConfig(
                'rankDimensions',
                {
                    rules: [
                        {
                            required: true,
                            message: '评定维度至少需要一条'
                        },
                        {
                            validator(_, value, callback) {
                                const message = '维度或者要求不能为空，维度数量不能大于20条，且要求字段最多200字符';
                                const validatorMap = {
                                    hasEmpty: {
                                        handler: () =>
                                            (value || []).some(item => {
                                                if (!item.dimensionTypeName || !item.demand) {
                                                    return true;
                                                }
                                                return false;
                                            })
                                    },
                                    isExceed: {
                                        handler: () => value && value.length > 20
                                    },
                                    hasMaxLen: {
                                        handler: () =>
                                            (value || []).some(item => {
                                                if (item.demand && item.demand.length > 200) {
                                                    return true;
                                                }
                                                return false;
                                            })
                                    }
                                };

                                const hasError = Object.keys(validatorMap).some(validatorKey => {
                                    const { handler } = validatorMap[validatorKey];
                                    if (handler()) {
                                        callback(message);
                                        return true;
                                    }
                                    return false;
                                });

                                if (!hasError) callback();
                            }
                        }
                    ]
                },
                fields
            );
        }
    }
    const getInitValue = (newRestQuery, prop, field, initialValue) => {
        if (prop === 'startTime' || prop === 'endTime') {
            return {
                ...initialValue,
                time: moment(newRestQuery[prop])
            };
        }
        // if (field.type === 'antd.Radio.Group') {
        //     return parseInt(restQuery[prop]);
        // }
        return newRestQuery[prop];
    };

    // 如果发现查询参数有初始值，则进行赋值
    Object.keys(restQuery).forEach(prop => {
        fields.forEach(field => {
            if (field.id === prop) {
                const curField = fields.find(item => item.id === prop) || {};
                const { component = {} } = curField.params;
                const { config = {} } = component;
                const { initialValue } = config;
                fields = modifyConfig(
                    prop,
                    {
                        initialValue: getInitValue(restQuery, prop, field, initialValue)
                    },
                    fields
                );
            }
        });
    });

    return {
        ...tmpJson,
        fields
    };
};

export default modifyJson;
